package com.lims.algorithm.useful.annotation.springfacade;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * <功能简述>
 *
 * @author: lims
 * @create: 2019-11-22 11:39
 */
@Component("default")
public class BaseFacadeImpl implements IBase, InitializingBean {
    @Resource
    private List<IBase> bases;

    private Map<String, IBase> pool = new ConcurrentHashMap<String, IBase>();

    @Override
    public String getKey() {
        return "default";
    }

    @Override
    public String getResult(String key) {
        IBase comp = pool.get(key);
        return comp.getResult(key);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        for (IBase comp :
                bases) {
            pool.put(comp.getKey(), comp);
        }
    }
}
